/*
 * 介绍:tabbar页数据管理
 */
import { defineStore } from "pinia";
import { apiHomeData, ApiHomeData } from "@@/api/module/tabbarPage";
import useBalanceStore from "./useBalanceStore";

export default defineStore("TabPageStore", {
  //*全局仓库
  state: initState,
  //*全局函数
  actions: {
    async getHomeData() {
      const res = await apiHomeData();
      if (!res) return;
      this.$patch((state) => (state.homeData = res));
      const balanceStore = useBalanceStore();
      balanceStore.approveAddresss = res.address.router_address
      return res;
    },
  },
  //*计算属性
  getters: {},
  //*仓库数据缓存
  persist: [
    {
      key: "TabPageStore",
      storage: localStorage, //指定储存位置
    },
  ],
});
/**state类型定义 */
interface TabPageStore {
  homeData: ApiHomeData.Data | undefined;
}

/**初始化pinia */
function initState(): TabPageStore {
  return {
    homeData: undefined,
  };
}
